var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function (req, res, next) {
  res.render('index', { title: 'Express' });
});

/***
 * 1. 请求登陆接口 use pwd 返回一个token
 * 
 * 2. 带上token去访问 获取用户信息接口：：拿到用户信息 getUserInfo接口，获取用户信息接口
 * 
 */
// 
router.post('/api/login', (req, res) => {
  res.status(200).send({
    code: 0,
    msg: 'success',
    data: {token: 'login_1803B_11_12'}
  })
})

router.get('/api/userInfo', (req, res) => {
  // 判断token符合不符合，如果符合才将用户信息传递出去
  res.send({
    code: 0,
    msg: 'success',
    data: {
      avatar: 'http://localhost:3000/images/title1.jpeg',
      name: 'devin',
      sex: 1,
      age: 1,
      userId: 1
    }
  })
})

router.get('/api/goods/list', function (req, res) {
  res.send({
    code: 0,
    msg: 'success',
    data: [
      {
        id: 1,
        "goods": "小米",
        price: '123'
      },
      {
        id: 2,
        "goods": "小米",
        price: '123'
      }
    ]
  })
})

router.get('/api/test', function (req, res) {
  res.send({
    code: 0,
    msg: 'success',
    data: [
      {
        "name": "devin",
        age: '123'
      },
      {
        "name": "age",
        age: '12'
      }
    ]
  })
})

module.exports = router;
